﻿using System;
using System.Data;
using Besture.Common;
using Besture.Dal;
using Besture.Model;

namespace Besture.Bll
{
    public partial class UserBaseDac : BaseFacade
    {
        //private readonly UserBaseDal excuteDal = new UserBaseDal();

        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="model">数据模型</param>
        /// <returns></returns>
        public int Add(UserBaseModel model)
        {
            try
            {
                base.CreateConnection(); 
                base.BeginTransaction();
                UserBaseDal excuteDal = new UserBaseDal();
                int lsRecord = 0;
                lsRecord = excuteDal.Add(model);
                if (lsRecord > 0)
                {
                    base.Commit();
                    return lsRecord;
                }
                else
                {
                    base.RollBack();
                    return -1;
                }
            }
            catch (Exception e)
            {
                base.RollBack();
                throw e;
            }
            finally
            {
                base.CloseConnection();
            }
        }

        
        /// <summary>
        /// 批量 审核
        /// </summary>
        /// <param name="idList"></param>
        /// <returns></returns>
        public int DeleteList(int iReviewerID ,int iCheckStatus, string sIds)
        {
            try
            {
                base.CreateConnection();
                base.BeginTransaction();
                UserBaseDal excuteDal = new UserBaseDal();
                int lsRecord = 0;
                lsRecord = excuteDal.DeleteList(iReviewerID,iCheckStatus,sIds);
                if (lsRecord > 0)
                {
                    base.Commit();
                    return lsRecord;
                }
                else
                {
                    base.RollBack();
                    return -1;
                }
            }
            catch (Exception e)
            {
                base.RollBack();
                throw e;
            }
            finally
            {
                base.CloseConnection();
            }
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">数据模型</param>
        /// <returns></returns>
        public int Update(UserBaseModel model) 
        {
            try
            {
                base.CreateConnection();
                base.BeginTransaction();
                UserBaseDal excuteDal = new UserBaseDal();
                int lsRecord = 0;
                lsRecord = excuteDal.Update(model);
                if (lsRecord > 0)
                {
                    base.Commit();
                    return lsRecord;
                }
                else
                {
                    base.RollBack();
                    return -1;
                }
            }
            catch (Exception e)
            {
                base.RollBack();
                throw e;
            }
            finally
            {
                base.CloseConnection();
            }
        }


        
        /// <summary>
        /// 获取数据模型
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
       public UserBaseModel GetModel(int id)
        {
            try
            {
                base.CreateConnection();
                UserBaseDal excuteDal = new UserBaseDal();
                return excuteDal.GetModel(id);
            }
            catch (Exception e)
            {
                throw e;
            }
           finally
            {
                 CloseConnection();
            }
        }

        public UserBaseModel GetDataByUser(string userName)
       {
           try
           {
               base.CreateConnection();
               UserBaseDal excuteDal = new UserBaseDal();
               return excuteDal.GetDataByUser(userName);
           }
           catch (Exception e)
           {
               throw e;
           }
           finally
           {
               CloseConnection();
           }
       }

        public int GetDataTableByPhoneOrEmail(string sPhoneEmail, int iUserType)
        {
            try
            {
                base.CreateConnection();
                UserBaseDal excuteDal = new UserBaseDal();
                return excuteDal.GetDataTableByPhoneOrEmail(sPhoneEmail, iUserType);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                CloseConnection();
            }
        }

        public DataTable GetDataTableByUserType(int iUserType)
       {
           try
           {
               base.CreateConnection();
               UserBaseDal excuteDal = new UserBaseDal();
               return excuteDal.GetDataTableByUserType(iUserType);
           }
           catch (Exception e)
           {
               throw e;
           }
           finally
           {
               CloseConnection();
           }
       }

        /// <summary>
       /// 获取全部数据
       /// </summary>
       /// <returns></returns>
       public DataTable GetDataTable()
        {
            try
            {
                base.CreateConnection();
                UserBaseDal excuteDal = new UserBaseDal();
                return excuteDal.GetDataTable();
            }
            catch (Exception e)
            {
                throw e;
            }
           finally
            {
               CloseConnection();
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        public int Delete(int id)
        {
            try
            {
                base.CreateConnection();
                UserBaseDal excuteDal = new UserBaseDal();
                return excuteDal.Delete(id);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
               CloseConnection();
            }
        }

        
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="idList">主键值集合</param>
        /// <returns></returns>
        public int DeleteList(string ids)
        {
            try
            {
                base.CreateConnection();
                UserBaseDal excuteDal = new UserBaseDal();
                return  excuteDal.DeleteList(ids);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
              CloseConnection();
            }
        }

        /// <summary>
        /// Register
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Register(UserBaseModel model)
        {
            try
            {
                base.CreateConnection();
                base.BeginTransaction();
                int lsRecord = 0;
                UserBaseDal excuteDal = new UserBaseDal();
                lsRecord = excuteDal.Register(model);
                if (lsRecord > 0)
                {
                    base.Commit();
                    return lsRecord;
                }
                else
                {
                    base.RollBack();
                    return -1;
                }
            }
            catch (Exception e)
            {
                base.RollBack();
                throw e;
            }
            finally
            {
                base.CloseConnection();
            }
        }
        /// <summary>
        /// Login
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public UserBaseModel Login(string UserName, string password)
        {
            try
            {
                CreateConnection();
                UserBaseDal excuteDal = new UserBaseDal();
                return excuteDal.Login(UserName, password);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                CloseConnection();
            }
        }
    }
}
